package sk.gtug.pivoplus.malepivo.model;

import java.util.ArrayList;
import java.util.List;

public class GeocodeResponse {
		
		//public List<Result> results;
		
		//@SerializedName("max_id")
		public String status;
		
		public List<GeocodeResponseResult> results;
		
		public GeocodeResponseResult getGeocodeResponseResultType(String type){
			for (GeocodeResponseResult result : results){
				if (result.types.contains(type))
					return result;
			}			
			return null;
		}
		
		public List<GeocodeResponseResult> getResultsByCountry(String country) {
			List<GeocodeResponseResult> tmp = new ArrayList<GeocodeResponseResult>();
			String longName;						
			
			for (GeocodeResponseResult result : results){
				longName = result.getAdressComponentType("country");
//				if (component != null && component.long_name.equalsIgnoreCase(country))
				if (longName != null && longName.equalsIgnoreCase(country))
					tmp.add(result);
			}			
			return tmp;
		}
		
		public GeocodeResponseResult getLocality() {
			GeocodeResponseResult result = null;
			result = getGeocodeResponseResultType("sublocality");
			if (result != null)
				return result;
			
			result = getGeocodeResponseResultType("locality");
			
			if (result != null)
				return result;
			
			if (results.size() > 0)
				return results.get(0);
			
			return null;
		}
}
